{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 25 - Hypothesis testing with multiple categories\n", "\n", "We will learn how to test hypotheses when our categorical data has more than two categories.\n", "\n", "First, let's import the necessary libraries." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Jury Panels in Alameda County 2009-2010\n", "\n", "We will look at jury panel data from 2009 and 2010 collected by the American Civil Liberties Union (ACLU). The total number of people who reported for jury duty in those years was 1,452. See [11.2 Multiple Categories](https://www.inferentialthinking.com/chapters/11/2/Multiple_Categories.html) for more information.\n", "\n", "We can create a dataframe with this data as shown below. " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# create a dictionary listing each column, followed by the column values in a list\n", "jury_data = {\"Eligible\":[0.15, 0.18, 0.12, 0.54, 0.01],\n", " \"Panels\":[0.26, 0.08, 0.08, 0.54, 0.04]}\n", "# pass the dictionary into the dataframe creation function as a parameter\n", "# also pass in labels for the rows\n", "jury = pd.DataFrame(data = jury_data, index = [\"Asian\",\"Black\",\"Latino/a\",\"White\",\"Other\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What do you think are the columns and rows of the new dataframe? Check your answer by displaying the dataframe `jury`. " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EligiblePanels
Asian0.150.26
Black0.180.08
Latino/a0.120.08
White0.540.54
Other0.010.04
\n", "
" ], "text/plain": [ " Eligible Panels\n", "Asian 0.15 0.26\n", "Black 0.18 0.08\n", "Latino/a 0.12 0.08\n", "White 0.54 0.54\n", "Other 0.01 0.04" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "jury" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will now make a bar chart of the two columns of data. Because our dataframe `jury` already contains counts of the different categories, we do not have to use the `value_count()` function. Instead, type `jury.plot(kind = \"bar\")` below." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEaCAYAAADqqhd6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAGVNJREFUeJzt3X+cVfV95/HXW4SMBEELs24fgM40aywoYGVAjIFQtXngj4Cr1UKajezq8kgiGyVNHsFmlxC0qbXUpKhZQlIbm/graN1FxVBNk0cSFcOQgETAgpaGsdkEiUFRUSZ+9o9zZrgMM8ydmTtzZr73/Xw87mPmnPO9937mPGbec+73fM/3KCIwM7O0HFN0AWZmVnkOdzOzBDnczcwS5HA3M0uQw93MLEEOdzOzBDnczcwS5HA3M0uQw93MLEHHFvXGo0aNirq6uqLe3sxsQNq4cePLEVHbWbvCwr2uro7Gxsai3t7MbECS9G/ltHO3jJlZghzuZmYJcribmSWosD53M6tuBw8epKmpiQMHDhRdSr9UU1PDmDFjGDx4cLee73A3s0I0NTVx/PHHU1dXh6Siy+lXIoK9e/fS1NREfX19t17D3TJmVogDBw4wcuRIB3s7JDFy5MgefapxuJtZYRzsHevpvnG4m5klyH3uZgmrW/xoj56/q+bDPS9i6b6ymvW01rZ23Xxxp20GDRrEhAkTWpfnzp3L4sWLmTlzJsuXL6ehoYGLLrqIe+65hxNOOKHD11myZAkzZszgggsuaL1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VhXup/Ga3VwB/EhHnd9be0iPpHLIAux74Usmm4WR/xJMKKawAkj5Jti/eRzbO/amSx5aIGBC3l6skSedx6LaDWyPiu0XW0xVVHe5m+bTPM4GPAStLNr0GPBwRO4qoqwiSbiUf2+6pBwY+h7sZ2Rw7EfFvRddhVinVdELV7GjeyK9QPR2oaVlZjRcxWRqqbmpXsw7cTTYKoh74AtlViRuKLMisJ9wtY0Z2D9WImNzmpiUbImJK0bWZdYe7ZcwyLXOF/ELSxWSX3P/OUdqb9WsOd7PMTZJGkF24cxvZUMjriy3JrPvcLWPWAUnXR0TVTSpnaXC4m3VA0s8j4uSi6zDrDo+WMetYNc89ZAOcw92sY/5YawOWT6haVZP0Gu2HeMuEamYDkvvczcwS5G4ZM7MEOdzNzBLkcDczS5DD3cwsQQ53M7ME/X/KUJIaSxdBvQAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "jury.plot(kind = \"bar\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "How does the distribution of eligible jurors compare with the distribution of the jury panels?\n", "\n", "To know whether the variation between the distributions is just the result of chance, we can compute a random sample from the eligible distribution and compare it with the panel distribution.\n", "\n", "First we create a variable for the eligible population and distribution." ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "population = [\"Asian\",\"Black\",\"Latino/a\",\"White\",\"Other\"]\n", "pop_prob = [0.15, 0.18, 0.12, 0.54, 0.01]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can create a sample from this population. The sample should be the same size as our data." ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array(['White', 'Other', 'Asian', ..., 'Asian', 'White', 'Asian'],\n", " dtype=' Answer:\n", " sample_probs = pd.Series(sample).value_counts(normalize = True)\n", "\n", "\n", "\n", "Next we will create a new column in our dataframe called `Random` that contains the probabilities from our random sample. To do this, type `jury[\"Random\"] = sample_probs` below and run it." ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "jury[\"Random\"] = sample_probs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Display the `jury` dataframe again to check that the column was added." ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EligiblePanelsRandom
Asian0.150.260.146006
Black0.180.080.180441
Latino/a0.120.080.121901
White0.540.540.539256
Other0.010.040.012397
\n", "
" ], "text/plain": [ " Eligible Panels Random\n", "Asian 0.15 0.26 0.146006\n", "Black 0.18 0.08 0.180441\n", "Latino/a 0.12 0.08 0.121901\n", "White 0.54 0.54 0.539256\n", "Other 0.01 0.04 0.012397" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "jury" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the bar chart of the dataframe again, and the new column will be included." ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEaCAYAAADqqhd6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAHCBJREFUeJzt3X90VeWd7/H3BwQjBaFiameJmtxeq4ABgYBQC7X1x0KL4K1jB1pbtLasqkzV/ljFeq91sNNxHGs7IL2UdvxRq2itdYoV61SHrtYftASFIoqCDkqYXouoKCpK9Hv/2DvhJCbkJDnJJvt8XmudRfbez9nne84in+zz7Gc/WxGBmZnlS5+sCzAzs9JzuJuZ5ZDD3cwshxzuZmY55HA3M8shh7uZWQ453M3McsjhbmaWQw53M7Mc2i+rFz744IOjqqoqq5c3M+uVVq9e/WJEVLbXLrNwr6qqoq6uLquXNzPrlSQ9V0w7d8uYmeWQw93MLIcc7mZmOZRZn7uZlZfdu3dTX1/Prl27si6lV6ioqGDYsGH069evU893uJtZj6ivr2fQoEFUVVUhKety9mkRwfbt26mvr6e6urpT+3C3jJn1iF27djF06FAHexEkMXTo0C59y3G4m1mPcbAXr6uflcPdzCyH3OdulmNV8+4puu3mis8Uv+MrdnSimuY6UlsxNl/1yXbb9O3bl5qamqblmTNnMm/ePE444QSuueYaamtrOe2007j11lsZMmRIm/u5/PLLmTJlCieddFLTBZkHH3xwszZXXHEFAwcO5Otf/3rn31QXONzNrMNqbqppv1Fq3ex13VhJxxxwwAGsWbNmr22WL1/e7n7mz59fqpK6jbtlzMwKVFVV8eKLLwJw5ZVXctRRR/HRj36UWbNmcc011wBwzjnn8Itf/KLpOVdffTU1NTVMmDCBTZs2vWefzzzzDFOnTmXcuHFMnjyZDRs2dPv7cLibWdl48803OfbYY5set99+e5ttV61axZ133snatWu599579zoX1uDBg1m3bh1z587l4osvfs/2OXPmsHDhQlavXs0111zDBRdcUJL3szfuljGzslFMt0yjhx56iBkzZlBRUUFFRQWnn356m21nzZrV9O8ll1zSbNvOnTt5+OGHOeuss5rWvfXWW52ovmMc7mZmXVQ4bLHlEMZ3332XIUOGFP1HpVTcLWNm1orjjz+eu+++m127drFz505+/etft9m2sXvn9ttvZ9KkSc22HXjggVRXV3PHHXcAydWna9eu7b7CUz5yN7NMFDN0sdQa+9wbTZ06lauuuqrVtuPHj2f69OmMGjWKQw45hJqaGgYPHtxq25dffplRo0ax//77s3Tp0vdsv+WWWzj//PP5zne+w+7du5k5cyajR48uzZtqgyKiW1+gLbW1teGbdZh1r+4a515TfXjR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eHUDouWXMLBtFDF3sCVOnTmXx4sUMHz6co446iokTJ7b7nAULFnDhhRcyatQoGhoamDJlyntG3nzjG99g48aNRAQnnnhit0/x25Kn/DXLMU/527t1Zcpfd8uYmeWQw93MLIcc7mZmOeRwNzPLIYe7mVkOOdzNzHLI49zNLBM1N9WUdH+NQy73pnDK3+rqam6++WaGDBnS5dfevHkz06ZN4/HHH+/yvkrFR+5mVjYKp/w96KCDWLRoUdYldRuHu5mVpUmTJrF1azJ7+c6dOznxxBMZO3YsNTU1/OpXvwKSI/Lhw4fzpS99iZEjR3LKKafw5ptvArB69WpGjx7N6NGjm/2R2LVrF+eeey41NTWMGTOGFStWAMmNPM444wxOPvlkqqqquO6667j22msZM2YMEydO5KWXXirp+3O4m1nZeeedd3jggQeYPn06ABUVFdx11108+uijrFixgq997Ws0Xr2/ceNGLrzwQtavX8+QIUO48847ATj33HNZuHAha9eubbbvRYsWIYl169axdOlSZs+e3TQR2eOPP84vf/lLVq1axWWXXcaAAQN47LHHmDRpEj/96U9L+h4d7mZWNhqn/P3gBz/ICy+8wMknnwxARPCtb32LUaNGcdJJJ7F169amG3NUV1c3TRM8btw4Nm/ezCuvvMIrr7zSdBOOz33uc02v8eCDD3L22WcDcPTRR3PEEUfw9NNPA/Dxj3+cQYMGUVlZyeDBgzn99NMBqKmpYfPmzSV9rw53MysbjX3uzz33HBHR1J1yyy23sG3bNlavXs2aNWs45JBDmo62999//6bnF0772xmF++rTp0/Tcp8+fbq039Y43M2s7AwYMIAFCxbwve99j4aGBnbs2MEHPvAB+vXrx4oVK3juuef2+vwhQ4YwZMgQHnzwQSD549Bo8uTJTctPP/00zz//PEcddVT3vZk2eCikmWWimKGL3WnMmDGMGjWKpUuX8tnPfpbTTz+dmpoaamtrOfroo9t9/g033MAXvvAFJHHKKac0rb/gggs4//zzqampYb/99uPGG29sdsTeUzzlr1mOecrf3s1T/pqZWTMOdzOzHHK4m1mPyaobuDfq6mflcDezHlFRUcH27dsd8EWICLZv305FRUWn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yy+PIZ4/DSaZ73ghsBeqBV/b6jPyK1ronI+IdSb3i/0U5hfunSC6zXyHpN8BtNL9KtdwU3nDgzRbbesV/3lKIiB+lP94fEQ8VbkvHvpeNiJia3jN0JEl/+9eAYyS9BDwSEd/OtMCe9UTaPdlsyoX02pgNGdXUIWXTLdNI0vuAGSTdM58Afgrc1XgUWy4kvQO8TvIH7gDgjcZNQEVE9Muqtiz05vHM3UHSMOB4kpCfBgyNiCF7f1Z+SDqUZOTUmyTXPkBykvkA4H/1hjn+yy7cC6U3uz0L+LuIOLG99pY/kiaRBNjFwPcLNh1I8ks8OpPCMiDpKySfxUdIxrk/XPBYFxG94vZypSTpE+y57eATEfFAlvV0RFmHu1k67fMJwJeBxQWbXgPujoiNWdSVBUnXko5t99QDvZ/D3Yxkjp2IeC7rOsxKpZxOqJrtzRvpFaojgYrGleV4EZPlQ9lN7WrWhltIRkFUA/9AclXiqiwLMusKd8uYkdxDNSLGtbhpyaqIGJ91bWad4W4Zs0TjXCF/kfRJkkvuD9pLe7N9msPdLPEdSYNJLtxZSDIU8uJsSzLrPHfLmLVB0sURUXaTylk+ONzN2iDp+Yg4POs6zDrDo2XM2lbOcw9ZL+dwN2ubv9Zar+UTqlbWJL1G6yHeOKGaWa/kPnczsxxyt4yZWQ453M3McsjhbmaWQw53M7MccribmeXQ/wfG+aW0GxCoxAAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "jury.plot(kind = \"bar\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "How does the distribution of the random sample compare to the eligible distribution? To the panel distribution?\n", "\n", "Let's compare the panels distribution to the eligible distribution quantitatively using hypothesis testing. We need to choose a statistic to simulate, called the *test statistic*. In this problem, we will use something called the *Total Variation Distance (TVD)* as the test statistic. The TVD measures the difference between two distributions. \n", "\n", "First we will compute the TVD between the panels and eligible distribution:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EligiblePanelsRandomDifference
Asian0.150.260.1460060.11
Black0.180.080.180441-0.10
Latino/a0.120.080.121901-0.04
White0.540.540.5392560.00
Other0.010.040.0123970.03
\n", "
" ], "text/plain": [ " Eligible Panels Random Difference\n", "Asian 0.15 0.26 0.146006 0.11\n", "Black 0.18 0.08 0.180441 -0.10\n", "Latino/a 0.12 0.08 0.121901 -0.04\n", "White 0.54 0.54 0.539256 0.00\n", "Other 0.01 0.04 0.012397 0.03" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "jury[\"Difference\"] = jury[\"Panels\"] - jury[\"Eligible\"]\n", "jury" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is the sum of the difference column? \n", "\n", "To fix this, we will take the absolute differences between probabilities." ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
EligiblePanelsRandomDifferenceAbsolute Difference
Asian0.150.260.1460060.110.11
Black0.180.080.180441-0.100.10
Latino/a0.120.080.121901-0.040.04
White0.540.540.5392560.000.00
Other0.010.040.0123970.030.03
\n", "
" ], "text/plain": [ " Eligible Panels Random Difference Absolute Difference\n", "Asian 0.15 0.26 0.146006 0.11 0.11\n", "Black 0.18 0.08 0.180441 -0.10 0.10\n", "Latino/a 0.12 0.08 0.121901 -0.04 0.04\n", "White 0.54 0.54 0.539256 0.00 0.00\n", "Other 0.01 0.04 0.012397 0.03 0.03" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "jury[\"Absolute Difference\"] = np.abs(jury[\"Difference\"])\n", "jury" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What does this do?\n", "\n", "Now take the sum of the absolute difference column. You can use the same command as when we took the sum of a filter." ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.28" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "jury[\"Absolute Difference\"].sum()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Answer:\n", " jury[\"Absolute Difference\"].sum()\n", "\n", "
\n", "\n", "Notice this sum is twice either the positive or negative count, so we divide it by two. This quantity is the *total variation distance (TVD)* between the distribution of ethnicity in the eligible juror population and the panel." ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.14" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_tvd = jury[\"Absolute Difference\"].sum()/2\n", "data_tvd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We could have done this calculation in one line of code:\n", "`np.abs(jury[\"Panel\"] - jury[\"Eligible\"]).sum()/2`\n", "Try it below." ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.14" ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.abs(jury[\"Panels\"] - jury[\"Eligible\"]).sum()/2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we want to understand the distribution of the test statistic (here, the TVD) if the panels were actually from the eligible distribution. To do this, we want to simulate random samples from the eligible distribution and compute the total variation distance between the sample and eligible distribution.\n", "\n", "First compute for one random sample, and compute the TVD between its probabilities and the eligible distribution." ] }, { "cell_type": "code", "execution_count": 74, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0019559228650137773" ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sample = np.random.choice(population,p = pop_prob,size = 1452)\n", "sample_probs = pd.Series(sample).value_counts(normalize = True)\n", "tvd = np.abs(sample_probs - jury[\"Eligible\"]).sum()/2\n", "tvd\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we want to repeat this process many times, and make a histogram of the difference TVD values. First, use a loop to generate many samples and compute the TVD to the eligible population." ] }, { "cell_type": "code", "execution_count": 75, "metadata": {}, "outputs": [], "source": [ "tvd_list = []\n", "for x in range(10000):\n", " sample = np.random.choice(population,p = pop_prob,size = 1452)\n", " sample_probs = pd.Series(sample).value_counts(normalize = True)\n", " tvd = np.abs(sample_probs - jury[\"Eligible\"]).sum()/2\n", " tvd_list.append(tvd)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next make the histogram of these simulated test statistics (the TVDs)." ] }, { "cell_type": "code", "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 80, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAD9dJREFUeJzt3X2MHPV9x/H3t3YAl0ttnnKiNskZhdIaTgnyCVKlke6gJCS0wVUQIkLUSLSnqE2VqkaKk7QSqfpgKlFaKZUiq4nif9qDolIsCE2Rw6VK1ZL4eOjxIIohh4rrgEKMm6OU6qpv/7hxdLj27ePs7v32/ZJWNzP7m5nv17v3ufHs7mxkJpKkte8n+l2AJKk7DHRJK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7wM+Olq+lLgcL/7qbHXnwTWV9PnA68enx+0Wyd9rrj/XuBvgNv63U+Nj+kY8FS/ezjZrVdH6D++TEBm/g9w/DIBK10H7Kum7wWuioiols9k5luZ+T3gULW9QdV2r5n5RmZ+G/jv3pXbtk76fDwz/6Na/jSwISJO70nV7emk1//KzKVq+RnAIL9o1cnvKRGxA/gey4/poOuo10HVq0A/2WUCNp9qTPULcAw4p8l1B0knva4l3erzE8BjmflWTXV2Q0e9RsQVEfE0MA98akXAD5q2+4yIEeCzwBd7UGc3dPr83RoRj0fEtyLiQ3UX2yyvh66+iYhLgDuAD/e7ljpl5qPAJRHxc8C+iHgoM9fC/8JacTtwV2YuDvhBbDccAd6dma9FxHbg7yLiksz8z34X1qsj9GYuE/DjMRGxHtgIvNbkuoOkk17Xko76jIgtwH3Ar2bmC7VX25muPKaZ+SywyPLrBoOokz6vAP4kIhaA3wY+X33wcFC13Wt1+vc1gMycY/lc/M/UXnETehXozVwmYD+ws5q+HvhmLr8CsR+4sXrFeStwEfCdHtXdjk56XUva7jMiNgEPArsz8596VnH7Oul1axUGRMR7gJ8FFnpTdsva7jMzP5SZY5k5BvwZ8EeZOcjv1OrkMT0vlr8Pgoi4kOVMerFHda+uh68qfwz4N5b/mn2hWvb7wMer6TNYfnX8EMuBfeGKdb9Qrfcc8NF+v5Jcc68LwA9ZPpJ7mRNeeR+kW7t9Ar8LvAE8seL2rn73U1OvN7P8IuETwGPAjn73Utdzd8U2bmfA3+XS4WP6iRMe01/udy/Hb35SVJIK4SdFJakQBrokFcJAl6RCGOiSVAgDXZIKYaBLUiEMdEkqhIEuSYX4P08ioo4aXcvzAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "pd.Series(tvd_list).hist(density = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Does the test statistic computed from the data look like it comes from this distribution?" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.8" } }, "nbformat": 4, "nbformat_minor": 2 }